﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Util;

namespace Club
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Dictionary<string, object> sessionVar = (Dictionary<string, object>)Session["vars"];
            DAL.User user = (DAL.User)sessionVar["userVar"];
            if (user != null)
            {
                Label1.Text = "Welcome: " + user.FullName+"["+user.Name + "]! ";
                if ((Session["LastLogout"] as DateTime?).HasValue)
                {
                    Label1.Text+="Your last logout time was "+ (Session["LastLogout"] as DateTime?).Value.ToString();
                }
                LinkButton1.Visible = true;
                LnkChangePassword.Visible = true;
                if (user.RoleId != (short)ROLE_ENUM.ADMIN)
                    NavigationMenu.Items[4].Enabled = false;
            }
            else
            {
                Label1.Text = "Welcome Guest!";
                LinkButton1.Visible = false;
                LnkChangePassword.Visible = false; 
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("Default.aspx");
        }
    }
}
